/* 
 * File:   trie.h
 * Author: Luis Aguirre
 * Description: Provides a trie.
 *
 * Created on 24 de julio de 2013, 11:28 AM
 */

#ifndef TRIE_H
#define	TRIE_H

#include <vector>
#include <string>

struct TrieNode
{   
    TrieNode()
    {
        data = ' ';
        finalWord = false;
    }
    
    ~TrieNode() 
    {
    }
    
    char getData() 
    {
        return data; 
    }
    
    void setData(char c) 
    {
        data = c; 
    }
    
    bool isFinalWord() 
    {
        return finalWord; 
    }
    
    void setFinalWord() 
    {
        finalWord = true;
    }
    
    TrieNode* findChild(char c)
    {
        for (unsigned int i = 0; i < getChildren().size(); i++ )
        {
            TrieNode* tmp = getChildren().at(i);
            if ( tmp->getData() == c )
            {
                return tmp;
            }
        }
        return NULL;
    }
    
    void appendChild(TrieNode* child) 
    { 
        children.push_back(child); 
    }
    
    std::vector<TrieNode*> getChildren() 
    {
        return children;
    }

private:
    char data;
    bool finalWord;
    std::vector<TrieNode*> children; 
};

class Trie
{
public:
    
    Trie();
    
    ~Trie();
    
    void addWord(std::string word);
    
    bool searchWord(std::string word);
    
    
    
private:
    TrieNode* root;

};

#endif	/* TRIE_H */

